import com.mosesSupposes.fuse.*;
import com.Lithyem.LoaderQueue;
class com.Lithyem.NSGS.Profiles.ImageManager extends MovieClip{
	
	var holder_mc:MovieClip;
	var delay:Number = 3; // 3 seconds between images
	
	var images:Array;
	var index:Number;
	
	var clipIndexLookup:Array;
	
	var Controller:Object;
	
	function ImageManager(){
		images = new Array();
		
	}
	
	function init(d:Array, c:Object):Void{
		images = d;
		Controller = c;
		clipIndexLookup = new Array();
		loadAll();
		
	}
	
	function loadAll():Void{
	
		var loaderQ = new com.Lithyem.LoaderQueue();
		loaderQ.addEventListener("onQueueComplete", this);
		
	
	
		for(var i = 0; i < images.length; i++){
			var clip = holder_mc.createEmptyMovieClip('clip_'+i,holder_mc.getNextHighestDepth());
			clip._alpha = 0;

			clipIndexLookup[clip._name] = images[i].index;
			
			
			
			
			if(!_root.imagepath){
				var img = 'img/student/'+images[i].img;
			}else{
				var img = _root.imagepath + images[i].img;
			}
			
			loaderQ.addClip(img, clip);
		}
		loaderQ.loadAll();
		
	}
	
	function onQueueComplete():Void{
		// ready to begin
		
		Controller.slideShowReady();
		
		var clip  = holder_mc['clip_0'];
		var f = new Fuse(
			{target:clip, alpha:100, seconds:.3, ease:'easeInOutQuad'}
		);
		f.start();
	}
	

	
	function nextImage():Void{
		if(index == undefined){
			index = -1;
		}
		
		if(index == images.length-1){
			// call out COMPLETE to shell
			Controller.onPresentationComplete();
		}else{
			index++;
			onBeginFadeInClip();
		}	
		
		
	}
	
	function onFadeInClip():Void{
		_global.setTimeout(this,'nextImage',delay*2000);
		

	}
	
	function onBeginFadeInClip():Void{
		//Controller.onTextBlock();
		
		var clip  = holder_mc['clip_'+index];
		
		Controller.onBeginFadeInClip(clipIndexLookup[clip._name]);
		
		var f = new Fuse(
			{target:clip, alpha:100, seconds:.7, ease:'easeInOutQuad', delay:.3},
			{scope:this,func:'onFadeInClip'}
		);
		f.start();
		
	}
	
	function reset():Void{
		for(var i = 1; i < images.length; i++){
			var clip  = holder_mc['clip_'+i];
			clip._alpha = 0;
		}
		
		index = -1;
	}
	

	
}